using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace myGame
{
    public class Pokemom : Moveable
    {
        private int size;
        float scale = 1/5;
        int direction;
        int type;
        Random rnd;
        SpriteBatch spriteBatch;

        public Pokemom(Game game, int t)
            : base(game)
        {
            rnd = new Random();
            vitesse = rnd.Next(1, 3);
            type = t;
            switch (type)
            {
                case 1:
                    texture = Game.Content.Load<Texture2D>("image/ech");
                    break;
                case 2:
                    texture = Game.Content.Load<Texture2D>("image/nhim");
                    break;
                case 3:
                    texture = Game.Content.Load<Texture2D>("image/klong");
                    break;
            }
        }

        public void setType(int t)
        {
            type = t;
        }

        public Pokemom(Game game, int _x, int _y)
            : base(game, _x, _y)
        {
        }

        public override void Initialize()
        {
            direction = -1;
            size = 1;
            base.Initialize();
        }

        public float getScale()
        {
            return scale;
        }

        public void attaque(Principale pk)
        {
            if (pk == null)
                return;
            double distance = pk.getDistanceTo(this);
            if (distance > this.texture.Height + pk.getTexture().Height)
                return;
            if (isOnBoard())
            {
            }
            if (x < pk.getX())
                x -= vitesse*direction;
            if (x > pk.getX())
                x += vitesse*direction;
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            base.LoadContent();
        }

        public void setSize(int s)
        {
            size = s;
        }

        public override void Update(GameTime gameTime)
        {
            if (isOnBoard())
                direction = -direction;
            x += direction*vitesse;
            base.Update(gameTime);
        }


        public override void Draw(GameTime gameTime)
        {
            spriteBatch.Begin();
            spriteBatch.Draw(texture, new Rectangle((int)x, (int)y, (int)(texture.Width * size/5), (int)texture.Height * size / 5), Color.White);
            spriteBatch.End();
            base.Draw(gameTime);
        }
    }
}
